package com.itsv.cyzx.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.itsv.cyzx.bean.BuzhuBean;
import com.itsv.xhyy.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BuZhuListAdapter extends BaseAdapter {
	private Context con = null;
	private ArrayList<BuzhuBean> jlist = null;
	private HashMap<Integer, View> viewCache = null;
	private LayoutInflater inflater;

	private int[] colors = { R.color.listcolor2, R.color.listcolor };

	public BuZhuListAdapter(Context con, ArrayList<BuzhuBean> jlist) {
		this.con = con;
		this.jlist = jlist;
		viewCache = new HashMap<Integer, View>();
		this.inflater = LayoutInflater.from(this.con);
	}

	public void setData(ArrayList<BuzhuBean> jlist) {
		this.jlist = jlist;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return jlist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View cv = viewCache.get(position);
		if (cv == null) {
			cv = inflater.inflate(R.layout.buzhu_list_item, null);
			cv.setBackgroundResource(colors[position % 2]);
			holder = new ViewHolder();
			holder.timeView = (TextView) cv.findViewById(R.id.buzhu_item_time);
			holder.jineView = (TextView) cv.findViewById(R.id.buzhu_item_jine);
			cv.setTag(holder);
			viewCache.put(position, cv);
		} else {
			holder = (ViewHolder) cv.getTag();
		}
		final BuzhuBean mm = jlist.get(position);
		if (mm != null) {
			holder.timeView.setText(mm.getTime());
			holder.jineView.setText(mm.getJine());
		}
		return cv;
	}

	class ViewHolder {
		private TextView timeView, jineView;
	}
}
